package com.zd.springsecuritydemo.controller;

import com.zd.springsecuritydemo.pojo.entity.User;
import com.zd.springsecuritydemo.response.ResponseResult;
import com.zd.springsecuritydemo.service.LoginService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author ZhangDong
 * @date 2024/1/7 13:33
 */
@Controller
@RequestMapping("user")
@RequiredArgsConstructor
public class LoginController {
    private final LoginService loginService;

    @RequestMapping("login")
    @ResponseBody
    public ResponseResult login(User user) {
        return loginService.login(user);
    }

    @RequestMapping("logout")
    @ResponseBody
    public ResponseResult logout() {
        return loginService.logout();
    }

    @RequestMapping("hello")
    @ResponseBody
    public ResponseResult hello() {
        return new ResponseResult("hello");
    }

    @RequestMapping("preAuthorize")
    @ResponseBody
//    @PreAuthorize("hasAuthority('test111')")
    @PreAuthorize("@ex.hasAuthority('test111')")
    public ResponseResult preAuthorize() {
        return new ResponseResult("hello");
    }
}
